import sys
import os
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
from config import HOST
from api import log
class ApiRegisterLogin:
    def __init__(self, session):
        self.session = session 
        self.__url_img_code = HOST + "/common/public/verifycode1/{}"
        self.__url_phone_code = HOST + "/member/public/sendSms"
        self.__url_register = HOST + "/member/public/reg"
        self.__url_login = HOST + "/member/public/login"
        self.__url_login_status = HOST + "/member/public/islogin"
        pass
    #1.封装图片验证码接口
    def api_img_code(self, random):
        log.info("正在调用获取图片验证码接口,请求url:{}".format(self.__url_img_code.format(random)))
        return self.session.get(self.__url_img_code.format(random))
    
    #2.封装短信验证码接口
    def api_phone_code(self, phone, verifycode):
        #1.定义请求参数
        data = {
            "phone":phone,
            "verifyCode":verifycode,
            "type":"reg",
        }
        log.info("正在调用获取短信验证码接口,请求url:{},请求参数:{}".format(self.__url_img_code, data))
        return self.session.post(self.__url_phone_code, data=data)
    #3.封装注册接口
    def api_register(self, phone, password,verifycode, phone_code ):

        #1.定义请求参数
        data = {
            "phone":phone,
            "verifycode":verifycode,
            "type":"reg",
            "phone_code":phone_code,
            "password":password,
            "dy_server":"on",
            "invite_phone":"",
        }
        log.info("正在调用注册接口,请求url:{},请求参数:{}".format(self.__url_register, data))
        return self.session.post(self.__url_register, data=data)
    #4.封装登录接口
    def api_login(self, keywords="12300001233", password = "test123"):
        data = {
            "keywords":keywords,
            "password":password,
            
        }
        log.info("正在调用登录接口,请求url:{},请求参数:{}".format(self.__url_login, data))
        return self.session.post(self.__url_login, data=data)
        pass
    #5。封装查询登录接口
    def api_login_status(self):
        log.info("正在调用登录接口,请求url:{}".format(self.__url_login_status))
        return self.session.post(self.__url_login_status)
    pass
 